<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@taglib prefix="sj" tagdir="/WEB-INF/tags/spring-jquery-tags"%>
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags"%>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>
<script type="text/javascript">
	$(document).ready(function() {
		$('#pageTitle').text('<spring:message code="findKnowledgeManagement.heading" />');

		$("#editKnowledgeManagementForm").validate({
			rules : {
				partner : {
					required : true
				},
				acronym : {
					required : true
				},
				costCenterNumber : {
					required : true
				},
				projectTitle : {
					required : true
				},
				donoraward : {
					required : true
				},
				projectStartDate : {
					required : true
				},
				projectEndDate : {
					required : true
				},
				cipeprojecttype : {
					required : true
				},
				cipeprojectstatus : {
					required : true
				},
				region : {
					required : true
				},
				country : {
					required : true
				},
				seniorProgramOfficer : {
					required : true
				},
				programOfficer : {
					required : true
				},
				programAssistant : {
					required : true
				},
				managementFunds : {
					required : true
				}
			}
		});
	});


		$('#loginFormSubmit').click(function() {
		
		  var v1= $('#projectID').val();
		  var v2= $('#theme').val();
		  var v3= $('#initialProjectStartDate').val();
		  var v4= $('#finalProjectStartDate').val();
		  var v5= $('#region\\.id').val();
		  var v6= $('#country\\.id').val();
		  var v7= $('#cipeprojecttype\\.id').val();
		  var v8= $('#organizationtype\\.id').val();
		  var v9= $('#keywordId1').val();
		  var v10= $('#keywordId2').val();
		  var v11= $('#keywordId3').val();
		  if(v3 !=''|| v4 !=''){
		  
		      if(v3 ==''){
		      alert("Select start date or leave start data and end date blank"); 
		       return false;
		     }
		      if(v4 ==''){
		      alert("Select end date or leave start data and end date blank"); 
		       return false;
		     }else if(v3 !='' && v4 !=''){
		     	var date_ini = new Date(v3).getTime();
			    var date_end = new Date(v4).getTime();
			    if(date_ini>date_end){
		        	alert("start date should be before end date");
		        	return false;
		        }
		     }
		  }
		 if(v1!='' || v2!='' || v3!=''|| v4!='' || v5!='' || v6!='' || v7!='' || v8!='' || v9!='' || v10!='' || v11!=''){		    
		   return true;
		 }
		 alert("Please enter at least one filter criteria");
		 return false;
		});

	$('.edit-cipeproject-link').click(function() {
		loadDiv('content', 'showEditKnowledgeManagement.do?id=' + $(this).attr('cipeprojectId'));
	});
	$('.edit-cipeprojectsummary-link').click(function() {
		loadDiv('content', 'showCipeprojectSummary.do?id=' + $(this).attr('cipeprojectId'));
	});
	$('.edit-partnergrantview-link').click(function() {
		loadDiv('content', 'showEditPartnergrantView.do?id=' + $(this).attr('cipeprojectId'));
	});
	$(function() {
		$("#initialProjectStartDate").datepicker();
	});
	$(function() {
		$("#finalProjectStartDate").datepicker();
	});
	$(function() {
		$("#initialProjectEndDate").datepicker();
	});
	$(function() {
		$("#finalProjectEndDate").datepicker();
	});
	$('#export-results').click(function() {
		//loadDiv('content', 'showViewKnowledgeManagement.do?id=' + $(this).attr('cipeprojectId'));
	});
	function TableToExcel() {
		var strCopy = document.getElementById("cipeprojectListDiv").innerHTML;
		window.clipboardData.setData("Text", strCopy);
		var objExcel = new ActiveXObject("Excel.Application");
		objExcel.visible = true;

		var objWorkbook = objExcel.Workbooks.Add;
		var objWorksheet = objWorkbook.Worksheets(1);
		objWorksheet.Paste;
	}
	$('.close-button').click(function() {
		if (confirm('Are you sure you want to close the form?')) {
			window.location = '../secure/showDashboard.do';
		}
	});
	
    $('#check-all').click(function() {
        // alert(this.checked);       
        var checkBox = $('#paymentRqst input:checkbox');
        for(var i = 0; i < checkBox.length; i++) {
     	   checkBox[i].checked = this.checked;
        }
 	});	
</script>
<div id="findKnowledgeManagementDiv">
	<form:form name="editKnowledgeManagementForm" id="editKnowledgeManagementForm" action="findResultKnowledgeManagement.do" method="post" modelAttribute="cipeproject">
		<form:hidden path="id" />

		<div class="main_form">
			<div class="form_head">
				<div class="floatL" style="padding-top:5px;">
					<!-- a class="blue_btn" href="#">Instructions</a -->
				</div>	    	
	    		<a href="#" class="close-button gray_btn floatR">Close Form</a><br class="clear" />
	    	</div>
	        <div class="form_cont">
				<table>
					<tr class="row">
						<td class="input-field" colspan="5"><%@ include file="/common/messages.jsp"%></td>
					</tr>
					<tr class="row">
						<td class="label" nowrap><spring:message code="editKnowledgeManagement.label.projectID" /></td>
						<td class="input-field">
							<form:input path="projectID" cssClass="input-full-width text_white " />
							<form:errors path="projectID" cssClass="error" />
						</td>
						<td width="50">&nbsp;</td>
						<td class="label"><spring:message code="editKnowledgeManagement.label.theme" /></td>
						<td class="input-field">
							<form:select path="themColumn" cssClass="input-full-width text_white" id="theme">
								<form:option value="" label="Select" />
								<form:option value="themebusassocdev:25" label="Business Association Development" />
								<form:option value="themelegalregreform:25" label="Legal/Regulatory Reform" />
								<form:option value="themewomenyouth:25" label="Women/Youth" />
								<form:option value="themeaccesstoinfo:25" label="Access to Information" />
								<form:option value="themeinformalsectorproperty:25" label="Informal Sector/Property" />
								<form:option value="themecorruption:25" label="Corruption" />
								<form:option value="themecorporategovernance:25" label="Corporate Governance" />
								<form:option value="themedemocraticgovernance:25" label="Democratic Governance" />
								<%--<form:options items="${themeList}" /> --%>
							</form:select>
							<form:errors path="" cssClass="error" />
						</td>
					</tr>
					<tr class="row">
						<td class="label"><spring:message code="editKnowledgeManagement.label.startDateBetween" /></td>
						<td class="input-field">
							<form:input path="initialProjectStartDate" cssClass="input-full-width text_white" />
							<form:errors path="initialProjectStartDate" cssClass="error" />
						</td>
						<td width="50">&nbsp;</td>
						<td class="label"><spring:message code="label.and" /></td>
						<td class="input-field">
							<form:input path="finalProjectStartDate" cssClass="input-full-width text_white" /> 
							<form:errors path="finalProjectStartDate" cssClass="error" />
						</td>
					</tr>	
					<tr>
						<td class="label"><spring:message code="editKnowledgeManagement.label.region" /></td>
						<td class="input-field">
							<form:select path="region.id" cssClass="input-full-width text_white">
								<form:option value="" label="Select" />
								<form:options items="${regionList}" itemValue="id" itemLabel="displayName" />
							</form:select>
							<form:errors path="region.id" cssClass="error" />
						</td>
						<td width="50">&nbsp;</td>
						<td class="label"><spring:message code="editKnowledgeManagement.label.country" /></td>
						<td class="input-field">
							<form:select path="country.id" cssClass="input-full-width text_white">
								<form:option value="" label="Select" />
								<form:options items="${countryList}" itemValue="id" itemLabel="displayName" />
							</form:select>
							<form:errors path="country.id" cssClass="error" />
						</td>
					</tr>
					<tr class="row">
						<td class="label"><spring:message code="editKnowledgeManagement.label.type" /></td>
						<td class="input-field">
							<form:select path="cipeprojecttype.id" cssClass="input-full-width text_white">
								<form:option value="" label="Select" />
								<form:options items="${cipeprojecttypeList}" itemValue="id" itemLabel="displayName" />
							</form:select>
							<form:errors path="cipeprojecttype.id" cssClass="error" />
						</td>
						<td width="50">&nbsp;</td>
						<td class="label"><spring:message code="editKnowledgeManagement.label.organizationtype" /></td>
						<td class="input-field"><form:select path="organizationtype.id" cssClass="input-full-width text_white">
								<form:option value="" label="Select" />
								<form:options items="${organizationtypeList}" itemValue="id" itemLabel="displayName" />
							</form:select>
							<form:errors path="organizationtype.id" cssClass="error" />
						</td>
					</tr>
					<tr class="row">
						<td class="label"><spring:message code="editKnowledgeManagement.label.keyword1" /></td>
						<td class="input-field">
							<form:select path="keywordId1" cssClass="input-full-width text_white">
								<form:option value="" label="Select" />
								<form:options items="${keywordList}" itemValue="id" itemLabel="displayName" />
							</form:select>
						</td>
						<td width="50">&nbsp;</td>
						<td class="label"><spring:message code="editKnowledgeManagement.label.condition" /></td>
						<td class="input-field">
							<form:select path="condition1" cssClass="input-full-width text_white">
								<form:option value="Or" label="Or" />
								<form:option value="And" label="And" />
							</form:select>
						</td>
					</tr>
					<tr class="row">
						<td class="label"><spring:message code="editKnowledgeManagement.label.keyword2" /></td>
						<td class="input-field">
							<form:select path="keywordId2" cssClass="input-full-width text_white">
								<form:option value="" label="Select" />
								<form:options items="${keywordList}" itemValue="id" itemLabel="displayName" />
							</form:select>
						</td>
						<td width="50">&nbsp;</td>
						<td class="label"><spring:message code="editKnowledgeManagement.label.condition" /></td>
						<td class="input-field">
							<form:select path="condition2" cssClass="input-full-width text_white">
								<form:option value="Or" label="Or" />
								<form:option value="And" label="And" />
							</form:select>
						</td>
					</tr>
					<tr class="row">
						<td class="label"><spring:message code="editKnowledgeManagement.label.keyword3" /></td>
						<td class="input-field">
							<form:select path="keywordId3" cssClass="input-full-width text_white">
								<form:option value="" label="Select" />
								<form:options items="${keywordList}" itemValue="id" itemLabel="displayName" />
							</form:select>
						</td>
						<td width="50">&nbsp;</td>
						<td class="label"><spring:message code="editKnowledgeManagement.label.condition" /></td>
						<td class="input-field">
							<form:select path="condition3" cssClass="input-full-width text_white">
								<form:option value="Or" label="Or" />
								<form:option value="And" label="And" />
							</form:select>
						</td>
					</tr>
					<tr>
		                <td align="right">&nbsp;</td>
		                <td>&nbsp;</td>
		                <td width="50">&nbsp;</td>
		                <td align="right">&nbsp;</td>
		              	<td></td>
		           	</tr>
		           	<tr>
		                <td align="center" colspan="5">
		                	<sj:submit id="loginFormSubmit" cssClass="gray_btn" target="findKnowledgeManagementDiv" key="button.search" validate="true" tabindex="-1"/>
		                	<input type="reset" class="blue_btn" value="<spring:message code='button.resetSearch' />" tabindex="-1"/>
		                </td>
		          	</tr>
					<tr>
		                <td align="right">&nbsp;</td>
		                <td>&nbsp;</td>
		                <td width="50">&nbsp;</td>
		                <td align="right">&nbsp;</td>
		                <td></td>
		          	</tr>		          	
		          	
				</table>
				<div id="cipeprojectListDiv" class="hastable" style="overflow: auto">
					<table class="tablesorter">
				 <c:choose>
					<c:when test="${!empty cipeprojectList}">
							<thead>
								<tr>
								 <th nowrap>&#10;<input type="checkbox" id="check-all"><spring:message code="common.select.all"/></th>
									<th><spring:message code="knowledgeManagementlist.table.heading.projectID" /></th>
									<th><spring:message code="knowledgeManagementlist.table.heading.startDate" /></th>
									<th><spring:message code="knowledgeManagementlist.table.heading.endDate" /></th>
									<th><spring:message code="knowledgeManagementlist.table.heading.acronym" /></th>
									<th><spring:message code="knowledgeManagementlist.table.heading.partner" /></th>
									<th><spring:message code="knowledgeManagementlist.table.heading.region" /></th>
									<th><spring:message code="knowledgeManagementlist.table.heading.country" /></th>
									<%--<th><spring:message code="knowledgeManagementlist.table.heading.impact" /></th> --%>
									<th><spring:message code="knowledgeManagementlist.table.heading.status" /></th>
									<th><spring:message code="knowledgeManagementlist.table.heading.organizationtype" /></th>
									<th><spring:message code="knowledgeManagementlist.table.heading.managementFunds" /></th>
									<!--th><spring:message code="knowledgeManagementlist.table.heading.view" /></th-->
									<!--th nowrap><spring:message code="knowledgeManagementlist.table.heading.viewProjectGrant" /></th-->
								</tr>
							</thead>
						
						<tbody id="paymentRqst">
							<c:forEach items="${cipeprojectList}" var="cipeproject">
								<tr> <td><input type="checkbox" name="check_element" value="${cipeproject.id}"></td>
									<td><a href="javascript://" class="edit-cipeproject-link" cipeprojectId="${cipeproject.id}">${cipeproject.projectID}</a></td>
									<td><fmt:formatDate pattern="MM-dd-yyyy" value="${cipeproject.projectStartDate}" /></td>
									<td><fmt:formatDate pattern="MM-dd-yyyy" value="${cipeproject.projectEndDate}" /></td>
									<td>${cipeproject.acronym}</td>
									<td>${cipeproject.partner.partnerName}</td>
									<td>${cipeproject.region.displayName}</td>
									<td>${cipeproject.country.displayName}</td>
									<%-- <td>${cipeproject.impact.displayName}</td>  --%>
									<td>${cipeproject.cipeprojectstatus.displayName}</td>
									<td>${cipeproject.organizationtype.displayName}</td>
									<c:choose>
										<c:when test="${cipeproject.cipeprojecttype.displayName=='Partner'}">
											<td><spring:message code="label.dollar"></spring:message>${cipeproject.partnerBudgetAmount}</td>
											<!--td><a href="javascript://" class="edit-cipeproject-link" cipeprojectId="${cipeproject.id}"><spring:message code="label.view" /></a></td -->
											<!--td align="center"><a href="javascript://" class="edit-partnergrantview-link" cipeprojectId="${cipeproject.id}"><spring:message code="label.view" /></a></td-->
										</c:when>
										<c:otherwise>
											<td><spring:message code="label.dollar"></spring:message></td> 
											<!--td><a href="javascript://" class="edit-cipeproject-link" cipeprojectId="${cipeproject.id}"><spring:message code="label.view" /></a></td-->
											<!--td align="center"><a href="javascript://" class="edit-cipeprojectsummary-link" cipeprojectId="${cipeproject.id}"><spring:message code="label.view" /></a></td-->
										</c:otherwise>
									</c:choose>
								</tr>
							</c:forEach>
						     <tr align="center"><td align="left" colspan="12"><input type="button" class="blue_btn" name="view" value="View Knowledge Management Catalogue Results" align="center" tabindex="-1">&nbsp;&nbsp;&nbsp;<input type="button"  class="blue_btn" name="view" value="View Project/Grant Details" align="center" tabindex="-1"></td></tr>						
						  </c:when>
							<c:otherwise>
							<c:if test="${ !empty param.action}">					  
								   <tr><td colspan="12"> Your query has returned 0 records </td></tr>
								 </c:if>  
							</c:otherwise>
				</c:choose>			
						</tbody>
					</table>
				</div>
				<div id="cipeprojectListPager"></div>
			</div>
		</div>
	</form:form>
</div>
